<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
</head>

<body>
    <div id="app">
        <label>
            输入个人所得：
            <input type="text" v-model="money">
        </label>
        <button @click="getTax()">
            计算个人所得税
        </button>
        <div>您得个人所得税为：{{tax}}</div>
    </div>

    <script>
        new Vue({
            el: "#app",
            data: {
                money: '',
                tax: ''
            }, methods: {
                getTax() {
                    fetch("http://localhost:9090/webservice/taxCalculatorService?wsdl", {
                        "headers": {
                            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
                            "accept-language": "en,zh;q=0.9,zh-CN;q=0.8,zh-TW;q=0.7,ja;q=0.6",
                            "cache-control": "no-cache",
                            "pragma": "no-cache",
                            "upgrade-insecure-requests": "1"
                        },
                        "referrerPolicy": "strict-origin-when-cross-origin",
                        "body": "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                            + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2003/XMLSchema-instance\" "
                            + "xmlns:web=\"http://service.taxCalculator.xtb.org/\"  "
                            + "xmlns:xsd=\"http://www.w3.org/2003/XMLSchema\" "
                            + "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                            + "<soap:Body>"
                            + "<web:calculateTax>"
                            + "<income>"
                            + `${this.money}`
                            + "</income>"
                            + "</web:calculateTax>"
                            + "</soap:Body>"
                            + "</soap:Envelope>",
                        "method": "POST",
                        "mode": "cors",
                        "credentials": "include"
                    }).then(
                        res=>{
                            // 定义一个变量存储 调用从XML中提取节点数据方法 返回的数据
                            //getXMLNode()是提取节点数据方法
                            console.log(res)
                            let resData=this.getXMLNode({xmlStr:res});
                            console.log(resData);
                            this.tax=resData
                        }

                    );
                },
                getXMLNode(param){
                    let str=param.xmlStr;
                    //创建文档对象

                    let xmlDoc = new DOMParser().parseFromString(str, "text/xml");
                    let finds=xmlDoc.getElementsByTagName('return');

                    return finds.nodeValue
                }
            }
        })
    </script>
</body>

</html>